package com.itetchologyandenglish.home.service.Impl;

import com.itetchologyandenglish.home.enetity.AuthUser;
import com.itetchologyandenglish.home.mapper.UserMapper;
import com.itetchologyandenglish.home.service.UserAthService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserAthServiceImpl implements UserAthService {
    @Resource
    UserMapper userAuthMapper;

    @Override
    public AuthUser loadUserByUsername(String username, String password) {
       return  userAuthMapper.loadUserByUsernameAndPassword(username,password);
    }

    @Override
    public boolean addUserByAll(AuthUser user) {
       return userAuthMapper.addUserByAll(user)>0?true:false;
    }

    @Override
    public int deleteByUser(Integer id) {
        return userAuthMapper.deleteByUser(id);
    }
    //@Transactional
    @Override
    public int deleteByAdmin(Integer id) {
        return userAuthMapper.deleteByAdmin(id);
    }

    @Override
    public int update(AuthUser user) {

       return userAuthMapper.update(user);
    }

    @Override
    public List<AuthUser> getAllUser() {
        return null;
    }

    @Override
    public boolean updatedelete(Integer id) {
        int flag= userAuthMapper.updatedelete(id);
        if(flag!=0){
            return true;
        }else{
            return false;
        }
    }
    @Override
    public boolean deactivate(Integer id) {
        if(userAuthMapper.deactivate(id)>0){
              return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean removeAdmin(Integer id) {
        return userAuthMapper.removeAdmin(id)>0? true:false;
    }

    @Override
    public AuthUser getUserById(Integer id) {
        return userAuthMapper.getUserById(id);
    }
}
